/**
 * Class: DGrid2
 *
 * Purpose: 
 *
 * Created: Jan 23, 2010 @ 11:06:19 PM
 * @author Ken Scott
 */
package org.openfantasia.util.math;

import org.openfantasia.util.Copyable;

public class DGrid2 implements Copyable<DGrid2> {

	private static final int N = 2;

	public double p[][][];


	public DGrid2() {
		p = new double[N][N][N];
	}


	public DGrid2(double[][][] p) {
		if (p[0][0].length != N) {
			throw new IllegalArgumentException("Input array must be of length " + N + ", not " + p[0][0].length);
		}
		this.p = Math3D.copy(p);
	}


	public DGrid2(DGrid2 p) {
		this(p.p);
	}


	public DGrid2 copy() {
		return new DGrid2(p);
	}

	public void copy(DGrid2 that) {
		p = Math3D.copy(that.p);
	}


	public DGrid2 clear() {
		Math3D.fill(p, 0);
		return this;
	}


	public double[][][] getValue() {
		return p;
	}


	public DGrid2 mulNoise(double frac) {
		p = Math3D.mulNoise(p, frac);
		return this;
	}


	public DGrid2 addNoise(double frac) {
		p = Math3D.addNoise(p, frac);
		return this;
	}


	public DGrid2 neg() {
		p = Math3D.neg(p);
		return this;
	}


	public DGrid2 abs() {
		p = Math3D.abs(p);
		return this;
	}


	public DGrid2 add(DGrid2 a) {
		if(a == null) {
			return this;
		}

		p = Math3D.add(p, a.p);
		return this;
	}


	public DGrid2 sub(DGrid2 a) {
		if(a == null) {
			return this;
		}

		p = Math3D.sub(p, a.p);
		return this;
	}


	public DGrid2 mul(DGrid2 a) {
		if(a == null) {
			return this;
		}

		p = Math3D.mul(p, a.p);
		return this;
	}


	public DGrid2 div(DGrid2 a) {
		if(a == null) {
			return this;
		}

		p = Math3D.div(p, a.p);
		return this;
	}
}